﻿using System;
using LayeredArchitectureSample.ViewModel;

namespace LayeredArchitectureSample.ClientBrowser
{
    class UserInteractionService : IUserInteractionService
    {
        /// <exception cref="ArgumentNullException"></exception>
        public void DisplayErrorMessage(Exception error)
        {
            if (error == null) throw new ArgumentNullException("error");

            var errorViewModel = new ErrorViewModel(
                error.Message,
                GetTechnicalDetailsFromError(error),
                Resources.ApplicationTitle);

            var errorView = new ErrorView(errorViewModel);

            errorView.ShowDialog();
        }

        private static string GetTechnicalDetailsFromError(Exception error)
        {
            if (error.InnerException != null)
            {
                return error.ToString();
            }

            return null;
        }

        /// <exception cref="ArgumentNullException"></exception>
        public void DisplayErrorMessageForUnknownErrorBeforeShutdown(Exception error)
        {
            if (error == null) throw new ArgumentNullException("error");

            var errorViewModel = new ErrorViewModel(
                Properties.Resources.UnexpectedErrorTerminatingApplication,
                error.ToString(),
                Resources.ApplicationTitle);

            var errorView = new ErrorView(errorViewModel);

            errorView.ShowDialog();
        }
    }
}